package com.bjbn.controller;

import com.bjbn.config.SystemConfig;
import com.bjbn.service.FimsDataService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.Map;

/**
 * FIMS数据控制器
 * 
 * @author bjbn
 */
@Slf4j
@RestController
@RequestMapping("/api/fims")
public class FimsDataController {

    @Autowired
    private FimsDataService fimsDataService;

    @Autowired
    private SystemConfig systemConfig;

    /**
     * 获取系统状态
     */
    @GetMapping("/status")
    public Map<String, Object> getStatus() {
        Map<String, Object> result = new HashMap<>();
        result.put("status", "running");
        result.put("mode", systemConfig.getMode());
        result.put("dataRetentionDays", systemConfig.getDataRetentionDays());
        result.put("timestamp", System.currentTimeMillis());
        return result;
    }

    /**
     * 手动触发数据清理
     */
    @PostMapping("/cleanup")
    public Map<String, Object> manualCleanup() {
        Map<String, Object> result = new HashMap<>();
        try {
            int deletedCount = fimsDataService.cleanExpiredData();
            result.put("success", true);
            result.put("deletedCount", deletedCount);
            result.put("message", "数据清理成功");
        } catch (Exception e) {
            log.error("手动数据清理失败", e);
            result.put("success", false);
            result.put("message", "数据清理失败: " + e.getMessage());
        }
        return result;
    }

    /**
     * 健康检查
     */
    @GetMapping("/health")
    public Map<String, Object> health() {
        Map<String, Object> result = new HashMap<>();
        result.put("status", "UP");
        result.put("service", "aesb-taom-aoip-api");
        result.put("timestamp", System.currentTimeMillis());
        return result;
    }
} 